﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL = KC.Business.BlogSlinger;
using DAL = KC.DataAccess.BlogSlinger;

public partial class Browse : System.Web.UI.Page
{
	protected void Page_Load(object sender, EventArgs e)
	{
		BindBlogs();
	}

	protected void dgBlogs_PageIndexChanged(object sender, DataGridPageChangedEventArgs e)
	{
		dgBlogs.CurrentPageIndex = e.NewPageIndex;
		BindBlogs();
	}
	protected void dgBlogs_ItemDataBound(object sender, DataGridItemEventArgs e)
	{
		if (e.Item.ItemType != ListItemType.Item && e.Item.ItemType != ListItemType.AlternatingItem)
			return;

		DAL.Blog blog = (DAL.Blog)e.Item.DataItem;
		HyperLink hlBlog = (HyperLink)e.Item.Cells[0].FindControl("hlBlog");
		hlBlog.NavigateUrl = "Blog.aspx?ID=" + blog.ID.ToString();
		hlBlog.Text = blog.Name;

		((Label)e.Item.FindControl("lblPosts")).Text = BLL.GetPostCount(ref Master.dc, blog.ID).ToString();
	}

	private void BindBlogs()
	{
		dgBlogs.DataSource = BLL.GetBlogs(ref Master.dc);
		dgBlogs.DataBind();
	}
}